// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.sprite;

import zombie.characters.IsoPlayer;
import zombie.core.Core;
import zombie.core.Styles.TransparentStyle;
import zombie.core.opengl.GLState;
import zombie.core.opengl.RenderSettings;
import zombie.core.textures.TextureFBO;
import zombie.input.Mouse;
import zombie.iso.PlayerCamera;

public final class SpriteRenderState extends GenericSpriteRenderState {
    public TextureFBO fbo = null;
    public long time;
    public final SpriteRenderStateUI stateUI;
    public int playerIndex;
    public final PlayerCamera[] playerCamera = new PlayerCamera[4];
    public final float[] playerAmbient = new float[4];
    public float maxZoomLevel = 0.0F;
    public float minZoomLevel = 0.0F;
    public final float[] zoomLevel = new float[4];

    public SpriteRenderState(int index) {
        super(index);

        for (int _int = 0; _int < 4; _int++) {
            this.playerCamera[_int] = new PlayerCamera(_int);
        }

        this.stateUI = new SpriteRenderStateUI(index);
    }

    @Override
    public void onRendered() {
        super.onRendered();
        this.stateUI.onRendered();
    }

    @Override
    public void onReady() {
        super.onReady();
        this.stateUI.onReady();
    }

    @Override
    public void CheckSpriteSlots() {
        if (this.stateUI.bActive) {
            this.stateUI.CheckSpriteSlots();
        } else {
            super.CheckSpriteSlots();
        }
    }

    @Override
    public void clear() {
        this.stateUI.clear();
        super.clear();
    }

    public GenericSpriteRenderState getActiveState() {
        return (GenericSpriteRenderState)(this.stateUI.bActive ? this.stateUI : this);
    }

    public void prePopulating() {
        this.clear();
        this.fbo = Core.getInstance().getOffscreenBuffer();

        for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
            IsoPlayer isoPlayer = IsoPlayer.players[_int];
            if (isoPlayer != null) {
                this.playerCamera[_int].initFromIsoCamera(_int);
                this.playerAmbient[_int] = RenderSettings.getInstance().getAmbientForPlayer(_int);
                this.zoomLevel[_int] = Core.getInstance().getZoom(_int);
                this.maxZoomLevel = Core.getInstance().getMaxZoom();
                this.minZoomLevel = Core.getInstance().getMinZoom();
            }
        }

        this.defaultStyle = TransparentStyle.instance;
        this.bCursorVisible = Mouse.isCursorVisible();
        GLState.startFrame();
    }
}
